package cc.lj.internal.coupons.interfaces.dto.convert;

import cc.lj.internal.coupons.domain.martcap.model.vo.MultipleModelDO;
import cc.lj.internal.coupons.interfaces.dto.MultipleModelDTO;
import cc.lj.internal.coupons.interfaces.dto.MultipleModelListDTO;
import cc.lj.internal.coupons.interfaces.dto.command.MultipleModelAddCommand;
import cc.lj.internal.coupons.interfaces.dto.command.MultipleModelUpdateCommand;
import cc.lj.internal.coupons.interfaces.dto.query.MultipleModelListQuery;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.math.BigDecimal;

@Mapper
public interface MultipleModelDTOConvertDO {
    MultipleModelDTOConvertDO INSTANCE = Mappers.getMapper(MultipleModelDTOConvertDO.class);

    //addCommand to do
   default MultipleModelDO convert(MultipleModelAddCommand multipleModelAddCommand)
   {
       MultipleModelDO multipleModelDO = new MultipleModelDO();
       multipleModelDO.setCapId(multipleModelAddCommand.getCapId());
       multipleModelDO.setDayNum(multipleModelAddCommand.getDayNum());
       //在转换的过程中，将小数点保留2位
       BigDecimal tmp = multipleModelAddCommand.getMultipleNum().setScale(2,BigDecimal.ROUND_DOWN);
       multipleModelDO.setMultipleNum(tmp);
       multipleModelDO.setModelValue(tmp+"*"+multipleModelAddCommand.getDayNum());
       return multipleModelDO;
   }
    //do to dto
    MultipleModelDTO convert(MultipleModelDO multipleModelDO);
    //updateCommand to do
    default MultipleModelDO convert(MultipleModelUpdateCommand multipleModelUpdateCommand)
    {
        MultipleModelDO multipleModelDO = new MultipleModelDO();
        multipleModelDO.setId(multipleModelUpdateCommand.getId());
        multipleModelDO.setCapId(multipleModelUpdateCommand.getCapId());
        multipleModelDO.setDayNum(multipleModelUpdateCommand.getDayNum());
        //在转换的过程中，将小数点保留2位
        BigDecimal tmp = multipleModelUpdateCommand.getMultipleNum().setScale(2,BigDecimal.ROUND_DOWN);
        multipleModelDO.setMultipleNum(tmp);
        multipleModelDO.setModelValue(tmp+"*"+multipleModelUpdateCommand.getDayNum());
        return multipleModelDO;
    }
    // listquery to do
    MultipleModelDO convert(MultipleModelListQuery query);

}
